package com.resume.controller;

import com.resume.bean.DataTableResponse;
import com.resume.bean.Result;
import com.resume.bean.ResultUtil;
import com.resume.constant.GlobalConst;
import com.resume.domain.City;
import com.resume.enums.ResultEnum;
import com.resume.ex.ResumeException;
import com.resume.service.CityService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Classname CityController
 * @Description nian
 * @Date 2021/7/18 20:10
 * @Created
 */
@Slf4j
@Controller
@RequestMapping("/city")
public class CityController {
    @Resource
    private CityService cityService;

    @GetMapping("/openCity")
    public String openProvince() {
        return "/base/city";
    }

    @ResponseBody
    @GetMapping("/v1/city")
    public Result<DataTableResponse<City>> list() {
        List<City> cityList = cityService.listAllUsablecity();

        DataTableResponse<City> dataTableResponse = new DataTableResponse<>();
        dataTableResponse.setSEcho(3);
        dataTableResponse.setITotalRecords(80);
        dataTableResponse.setITotalDisplayRecords(70);
        dataTableResponse.setAaData(cityList);
        return ResultUtil.success(200, "数据查询成功", dataTableResponse);
    }

    @ApiOperation(value = "删除省", notes = "根据编号删除省的状态")
    @ResponseBody
    @GetMapping("/v1/remove")
    public Result remove(Integer id) {
        try {
            cityService.modifyCityStatus(id, GlobalConst.Common.STATUS_DISABLE);
            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ResumeException(ResultEnum.SQL_ERROR);
        }
    }

}
